import json
import os
from Util.SQL import select

def get_config(profile, parameter):  # 返回配置文件中的信息
    # 构建完整路径
    json_path = 'Config/{profile}.json'.format(profile=profile)  # 获得文件相对路径
    join_path = get_path(os.path.abspath(__file__), 2, json_path)
    with open(join_path, 'r', encoding="utf-8") as file:
        config = json.load(file)
    return config[parameter]


def get_path(abspath, level, relpath):  # 返回路径
    path = os.path.join(abspath)
    for _ in range(level):  # 向上跳转几级目录至根目录
        path = os.path.dirname(path)

    path = os.path.join(path, relpath)
    return path


def get_dataset(image_name):  # 通过景号获取图片数据集
    model_id = image_name.split('.')[0]
    dataset = select(f"select dataset from data where scene_id = '{model_id}'")

    if len(dataset) != 0:
        return dataset[0]['dataset']
    else:
        return "TASK"